package com.somiz.structure;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;

import com.somiz.main.Control;
import com.somiz.objet.ObjetIdentifiableDaoImpl;

public class StructureDaoImpl extends ObjetIdentifiableDaoImpl<Structure>
		implements StructureDao {
	public Boolean isExisteAvecCode(Structure structure, Session session) {
		Boolean isExiste = false;
		Structure structureTest = new Structure();
		List<Structure> structures = Control.getStructureDao().charger(
				structureTest, session);
		for (int i = 0; i < structures.size(); i++) {
			if (structure.getCode().equals(structures.get(i).getCode())) {
				isExiste = true;
			}
		}
		return isExiste;
	}

	public Structure TrouverAvecCode(Structure structure, Session session) {
		Structure structureTest = new Structure();
		List<Structure> structures = Control.getStructureDao().charger(
				structureTest, session);
		for (int i = 0; i < structures.size(); i++) {
			if (structure.getCode().equals(structures.get(i).getCode())) {
				structure = structures.get(i);
			}
		}
		return structure;
	}

	public List<String> ListeCodesStructures(Session session) {
		Structure structureTest = new Structure();
		List<Structure> structures = Control.getStructureDao().charger(
				structureTest, session);
		List<String> CodesStructures = new ArrayList<>(0);
		CodesStructures.add("");
		for (int i = 0; i < structures.size(); i++) {
			CodesStructures.add(structures.get(i).getCode());
		}
		return CodesStructures;
	}

}
